{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 2 Python 字面量\n",
    "## 2.1 基本语法\n",
    "### 2.1.1 注释语句\n",
    "单行注释"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "天津大学\n",
      "精仪学院\n"
     ]
    }
   ],
   "source": [
    "print(\"天津大学\")\n",
    "# print(\"精仪学院\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-09T19:30:55.695643Z",
     "end_time": "2024-10-09T19:30:55.704456Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "多行注释"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "'''\n",
    "作者：郭泰瑞\n",
    "单位：天津大学\n",
    "'''"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "a = 1\n",
    "b = 2\n",
    "if a == b:\n",
    "    print(a)\n",
    "    print(b)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-09T19:40:36.621233Z",
     "end_time": "2024-10-09T19:40:36.625555Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sadasdada\n",
      "asdadawsd\n"
     ]
    }
   ],
   "source": [
    "print(\"sadasdada\\n\"\n",
    "      \"asdadawsd\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-09T19:48:12.449628Z",
     "end_time": "2024-10-09T19:48:12.527427Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "a = ['天津大学', '精仪学院','测控技术与仪器']"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 2.2 变量与数据类型\n",
    "### 与C语言不同，Python中的变量无需事先声明和定义，可直接使用。但变量仍具有烈性，变量类型一般在对变量赋值时确定"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 2.2.1 数据类型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "aaaa <class 'str'>\n",
      "(4+6j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "print(a, type(a))\n",
    "a = \"aaaa\"\n",
    "print(a, type(a))\n",
    "b = 3 + 4j\n",
    "c = 1 + 2j\n",
    "c += b\n",
    "print(c, type(c))\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-09T19:56:52.301071Z",
     "end_time": "2024-10-09T19:56:52.311160Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 2.2.2 布尔类型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True False <class 'bool'> <class 'bool'>\n",
      "a为假\n",
      "a为真\n"
     ]
    }
   ],
   "source": [
    "a = True\n",
    "b = False\n",
    "print(a , b , type(a) , type(b))\n",
    "a = \"\"\n",
    "if a:\n",
    "    print(\"a为真\")\n",
    "else:\n",
    "    print(\"a为假\")\n",
    "a = \"0\"\n",
    "if a:\n",
    "    print(\"a为真\")\n",
    "else:\n",
    "    print(\"a为假\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-09T20:01:08.683900Z",
     "end_time": "2024-10-09T20:01:08.688461Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 2.2.3 字符串类型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "天津大学精仪学院\n"
     ]
    }
   ],
   "source": [
    "name = \"天津大学\"\n",
    "a = '精仪学院'\n",
    "b = \"天津大学'精仪学院'\"\n",
    "print(name + a)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-09T20:07:37.609906Z",
     "end_time": "2024-10-09T20:07:37.616226Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 * 1 = 1 \n",
      "\n",
      "1 * 2 = 2 2 * 2 = 4 \n",
      "\n",
      "1 * 3 = 3 2 * 3 = 6 3 * 3 = 9 \n",
      "\n",
      "1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16 \n",
      "\n",
      "1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25 \n",
      "\n",
      "1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36 \n",
      "\n",
      "1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49 \n",
      "\n",
      "1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 \n",
      "\n",
      "1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 \n",
      "\n"
     ]
    }
   ],
   "source": [
    "i = 1\n",
    "while i < 10:\n",
    "    for a in range(1, 10, 1):\n",
    "        if a <= i:\n",
    "             print(f\"{a} * {i} = {i*a}\",end=' ')\n",
    "        else:\n",
    "            break\n",
    "    print(\"\\n\")\n",
    "    i += 1"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-09T20:21:28.859163Z",
     "end_time": "2024-10-09T20:21:28.864652Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
